﻿@model CustomerInfoModel
@using Nop.Web.Models.Customer;
@using Nop.Core;
@{
    Layout = "~/Views/Shared/_ColumnsTwo.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.Account").Text);
}
@section left
{
    @Html.Partial("MyAccountNavigation", Model.NavigationModel, new ViewDataDictionary())
}
@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <script type="text/javascript">
     $(function() {
            $("#@Html.FieldIdFor(model => model.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
                var statesProgress = $("#states-loading-progress");
                statesProgress.show();
                $.ajax({
                    cache: false,
                    type: "GET",
                    url: "@(Url.RouteUrl("GetStatesByCountryId"))",
                    data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
                    success: function (data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                        statesProgress.hide();
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to retrieve states.');
                        statesProgress.hide();
                    }  
                });
            });
        });
    </script>
}
<div class="page account-page customer-info-page">
    <div class="page-title">
        <h1>@T("Account.MyAccount") - @T("Account.CustomerInfo")</h1>
    </div>
    <div class="clear">
    </div>
    <div class="page-body">
        @using (Html.BeginForm())
        {
            @Html.AntiForgeryToken()
            <div class="message-error">
                @Html.ValidationSummary(true)
            </div>
            <div class="clear">
            </div>            
            <fieldset class="form-fields">
                <legend>@T("Account.YourPersonalDetails")</legend>
                <dl>
                    @if (Model.GenderEnabled)
                    {
                        <dt>
                            <label>@T("Account.Fields.Gender"):</label>
                        </dt>
                        <dd>
                            @Html.RadioButton("Gender", "M", (Model.Gender == "M"), new { id = "gender-male" })
                            <label class="forcheckbox" for="gender-male">@T("Account.Fields.Gender.Male")</label>
                            @Html.RadioButton("Gender", "F", (Model.Gender == "F"), new { id = "gender-female" })
                            <label class="forcheckbox" for="gender-female">@T("Account.Fields.Gender.Female")</label>
                        </dd>
                    }
                    <dt>
                        @Html.LabelFor(model => model.FirstName): </dt>
                    <dd>
                        @Html.EditorFor(model => model.FirstName)
                        @Html.RequiredHint()
                        @Html.ValidationMessageFor(model => model.FirstName)
                    </dd>
                    <dt>
                        @Html.LabelFor(model => model.LastName): </dt>
                    <dd>
                        @Html.EditorFor(model => model.LastName)
                        @Html.RequiredHint()
                        @Html.ValidationMessageFor(model => model.LastName)
                    </dd>
                    @if (Model.DateOfBirthEnabled)
                    {
                        <dt>
                            <label>@T("Account.Fields.DateOfBirth"):</label>
                        </dt>
                        <dd>
                            @Html.DatePickerDropDowns(Html.FieldNameFor(x => x.DateOfBirthDay),
                                        Html.FieldNameFor(x => x.DateOfBirthMonth),
                                        Html.FieldNameFor(x => x.DateOfBirthYear),
                                        DateTime.Now.Year - 110,
                                        DateTime.Now.Year,
                                        Model.DateOfBirthDay,
                                        Model.DateOfBirthMonth,
                                        Model.DateOfBirthYear)
                            @Html.ValidationMessageFor(model => model.DateOfBirthDay)
                            @Html.ValidationMessageFor(model => model.DateOfBirthMonth)
                            @Html.ValidationMessageFor(model => model.DateOfBirthYear)
                        </dd>
                    }
                    <dt>
                        @Html.LabelFor(model => model.Email): </dt>
                    <dd>
                        @Html.EditorFor(model => model.Email)
                        @Html.RequiredHint()
                        @Html.ValidationMessageFor(model => model.Email)
                    </dd>
                    @if (Model.UsernamesEnabled)
                    {
                        if (Model.AllowUsersToChangeUsernames)
                        {
                        <dt>
                            @Html.LabelFor(model => model.Username): </dt>
                        <dd>
                            @Html.EditorFor(model => model.Username)
                            @Html.RequiredHint()
                            @Html.ValidationMessageFor(model => model.Username)
                            @if (Model.CheckUsernameAvailabilityEnabled)
                            {
                                @Html.Partial("_CheckUsernameAvailability")
                            }
                        </dd>
                        }
                        else
                        {
                        <dt>
                            @Html.LabelFor(model => model.Username): </dt>
                        <dd>
                            @Model.Username
                        </dd>
                        }
                    }
                </dl>
            </fieldset>    
                    if (Model.AssociatedExternalAuthRecords.Count > 0)
                    {
            <fieldset class="form-fields">
                <legend>@T("Account.AssociatedExternalAuth")</legend>
                <dl>
                    <dd>
                        <table class="data-table">
                            <col />
                            <col />
                            <col />
                            <thead>
                                <tr>
                                    <th class="a-center">
                                        @T("Account.AssociatedExternalAuth.AuthMethodName")
                                    </th>
                                    <th class="a-center">
                                        @T("Account.AssociatedExternalAuth.Email")
                                    </th>
                                    <th class="a-center">
                                        @T("Account.AssociatedExternalAuth.ExternalIdentifier")
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model.AssociatedExternalAuthRecords)
                                {
                                    <tr>
                                        <td class="a-left">
                                            @item.AuthMethodName
                                        </td>
                                        <td class="a-left">
                                            @item.Email
                                        </td>
                                        <td class="a-left">
                                            @CommonHelper.EnsureMaximumLength(item.ExternalIdentifier, 40, "...")
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </dd>
                </dl>
            </fieldset>
                    }
                    if (Model.CompanyEnabled || Model.DisplayVatNumber)
                    {
            <fieldset class="form-fields">
                <legend>@T("Account.CompanyDetails")</legend>
                <dl>
                    @if (Model.CompanyEnabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.Company): </dt>
                        <dd>
                            @Html.EditorFor(model => model.Company)
                            @if (Model.CompanyRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.Company)
                        </dd>
                    }
                    @if (Model.DisplayVatNumber)
                    {
                        <dt>
                            @Html.LabelFor(model => model.VatNumber): </dt>
                        <dd>
                            @Html.EditorFor(model => model.VatNumber)&nbsp;&nbsp;&nbsp;@Model.VatNumberStatusNote
                            <span class="vat-note"><em>@T("Account.Fields.VatNumber.Note")</em></span>
                        </dd>
                    }
                </dl>
            </fieldset>
                    }
                    if (Model.StreetAddressEnabled ||
                                Model.StreetAddress2Enabled ||
                                Model.ZipPostalCodeEnabled ||
                                Model.CityEnabled ||
                                Model.CountryEnabled)
                    {                
            <fieldset class="form-fields">
                <legend>@T("Account.YourAddress")</legend>
                <dl>
                    @if (Model.StreetAddressEnabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.StreetAddress): </dt>
                        <dd>
                            @Html.EditorFor(model => model.StreetAddress)
                            @if (Model.StreetAddressRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.StreetAddress)
                        </dd>
                    }
                    @if (Model.StreetAddress2Enabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.StreetAddress2): </dt>
                        <dd>
                            @Html.EditorFor(model => model.StreetAddress2)
                            @if (Model.StreetAddress2Required)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.StreetAddress2)
                        </dd>
                    }
                    @if (Model.ZipPostalCodeEnabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.ZipPostalCode): </dt>
                        <dd>
                            @Html.EditorFor(model => model.ZipPostalCode)
                            @if (Model.ZipPostalCodeRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.ZipPostalCode)
                        </dd>
                    }
                    @if (Model.CityEnabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.City): </dt>
                        <dd>
                            @Html.EditorFor(model => model.City)
                            @if (Model.CityRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.City)
                        </dd>
                    }
                    @if (Model.CountryEnabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.CountryId): </dt>
                        <dd>
                            @Html.DropDownList("CountryId", Model.AvailableCountries)
                        </dd>
                    }
                    @if (Model.CountryEnabled && Model.StateProvinceEnabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.StateProvinceId): </dt>
                        <dd>
                            @Html.DropDownList("StateProvinceId", Model.AvailableStates)
                            <span id="states-loading-progress" style="display: none;" class="please-wait">@T("Common.Wait...")</span>
                        </dd>
                    }
                </dl>
            </fieldset>            
                    }
                    if (Model.PhoneEnabled || Model.FaxEnabled)
                    {
            <fieldset class="form-fields">
                <legend>@T("Account.YourContactInformation")</legend>
                <dl>
                    @if (Model.PhoneEnabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.Phone): </dt>
                        <dd>
                            @Html.EditorFor(model => model.Phone)
                            @if (Model.PhoneRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.Phone)
                        </dd>
                    }
                    @if (Model.FaxEnabled)
                    {
                        <dt>
                            @Html.LabelFor(model => model.Fax): </dt>
                        <dd>
                            @Html.EditorFor(model => model.Fax)
                            @if (Model.FaxRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.Fax)
                        </dd>
                    }
                </dl>
            </fieldset>
                    }
                    if (Model.NewsletterEnabled)
                    {
            <fieldset class="form-fields">
                <legend>@T("Account.Options")</legend>
                <dl>
                    <dt>
                        @Html.LabelFor(model => model.Newsletter): </dt>
                    <dd>
                        @Html.EditorFor(model => model.Newsletter)
                        @Html.ValidationMessageFor(model => model.Newsletter)
                    </dd>
                </dl>
            </fieldset>
                    }
                    if (Model.AllowCustomersToSetTimeZone || Model.SignatureEnabled)
                    {
            <fieldset class="form-fields">
                <legend>@T("Account.Preferences")</legend>
                <dl>
                    @if (Model.AllowCustomersToSetTimeZone)
                    {
                        <dt>
                            @Html.LabelFor(model => model.TimeZoneId):</dt>
                        <dd>
                            @Html.DropDownList("TimeZoneId", Model.AvailableTimeZones)
                            @Html.ValidationMessageFor(model => model.TimeZoneId)
                        </dd>
                    }
                    @if (Model.SignatureEnabled)
                    {                                    
                        <dt>
                            @Html.LabelFor(model => model.Signature):</dt>
                        <dd>
                            @Html.TextAreaFor(model => model.Signature, new { @class = "account-signature-text" })
                        </dd>
                    }
                </dl>
            </fieldset>
                    }
            <div class="clear">
            </div>
            <div class="buttons">
                <input type="submit" value="@T("Common.Save")" name="save-info-button" class="button-1 save-customer-info-button" />
            </div>
        }
    </div>
</div>
